package com.xiaouyudeguang.common.utils;

import com.xiaouyudeguang.common.event.LogEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class LogUtils {

    private static ApplicationContext context;

    public LogUtils(@Autowired(required = false) ApplicationContext context) {
        LogUtils.context = context;
    }

    public static void publish(LogEvent event) {
        context.publishEvent(event);
    }

    public static <T> void publish(String tenantId, String appId, T data) {
        context.publishEvent(new LogEvent(tenantId, appId, IdUtils.randomUUID(), data));
    }
}
